//=============================================================================
// FusionGatlingProj
//=============================================================================
class FusionGatlingProj extends TFProjectile;

var bool bRing,bHitWater,bWaterStart;
var int NumExtraRockets;
var	xEmitter SmokeTrail;
var Effects Corona;
var vector Dir;


simulated function Destroyed()
{
	if ( SmokeTrail != None )
		SmokeTrail.mRegen = False;
	if ( Corona != None )
		Corona.Destroy();
	Super.Destroyed();
}

simulated function PostBeginPlay()
{
	if ( Level.NetMode != NM_DedicatedServer)
	{
		SmokeTrail = none;	//Spawn(class'RocketTrailSmoke',self);
		Corona = none;	//Spawn(class'FusionGatlingCorona',self);
	}

	Dir = vector(Rotation);
	Velocity = speed * Dir;
	if (PhysicsVolume.bWaterVolume)
	{
		bHitWater = True;
		Velocity=0.6*Velocity;
	}
    if ( Level.bDropDetail )
	{
		bDynamicLight = false;
		LightType = LT_None;
	}
}

simulated function PostNetBeginPlay()
{
	Super.PostNetBeginPlay();
}

simulated function ProcessTouch (Actor Other, Vector HitLocation)
{
	local Vector X, RefNormal, RefDir;

	if (Other == Instigator) return;
	if (Other == Owner) return;

	    if (Other.IsA('xPawn') && xPawn(Other).CheckReflect(HitLocation, RefNormal, Damage*0.25))
	    {
	        if (Role == ROLE_Authority)
	        {
	            X = Normal(Velocity);
	            RefDir = X - 2.0*RefNormal*(X dot RefNormal);
	            //Log("reflecting off"@Other@X@RefDir);
	            Spawn(Class, Other,, HitLocation+RefDir*20, Rotator(RefDir));
	        }
//	        Destroy();
	    }
	    else if ( Other.IsA('ONSPowerCore') || Other.IsA('ONSPowerNode') || Other.IsA('ONSPowerNodeEnergySphere'))
		{
			if ( Role == ROLE_Authority )
			 Other.TakeDamage(7, Instigator, HitLocation, MomentumTransfer * Normal(Velocity), MyDamageType);

			if ( EffectIsRelevant(Location,false) )
			 Spawn(class'XEffects.ExploWallHit',,, HitLocation, Rotator(Instigator.Location - HitLocation));

			Destroy();
			return;
		}

	    else if ( !Other.IsA('Projectile') || Other.bProjTarget || Other.IsA('Vehicle'))
		{
			if ( Role == ROLE_Authority )
			Other.TakeDamage(Damage ,Instigator,HitLocation,MomentumTransfer*Normal(Velocity),MyDamageType);
		}

	Explode(Location,vect(0,0,1));
}

function BlowUp(vector HitLocation)
{
	HurtRadius(Damage, DamageRadius, MyDamageType, MomentumTransfer, HitLocation );
}

simulated function Explode(vector HitLocation, vector HitNormal)
{
    if ( EffectIsRelevant(Location,false) )
    {
	Spawn(class'XEffects.ExploWallHit',,, HitLocation, Rotator(HitNormal));

//	if ( (ExplosionDecal != None) && (Level.NetMode != NM_DedicatedServer) )
//		Spawn(ExplosionDecal,self,,Location, rotator(-HitNormal));

    }

	BlowUp(HitLocation);
	Destroy();
}

simulated function Timer()
{
    Velocity =  Default.Speed * Normal(Dir * 0.5 * Default.Speed + Velocity);
}

defaultproperties
{
     Speed=4000.000000
     MaxSpeed=6000.000000
     Damage=1.000000
     DamageRadius=50.000000
     MomentumTransfer=5000.000000
     MyDamageType=Class'Taskforces.FusionGatlingDamType'
     DrawType=DT_Sprite
     AmbientSound=Sound'WeaponSounds.RocketLauncher.RocketLauncherProjectile'
     LifeSpan=7.000000
     Texture=Texture'TFMedia.Fusion.FusionFlare'
     DrawScale=0.750000
     Skins(0)=Texture'TFMedia.Fusion.FusionFlare'
     Style=STY_Translucent
     SoundVolume=255
     bFixedRotationDir=True
     RotationRate=(Roll=50000)
     DesiredRotation=(Roll=30000)
     ForceType=FT_Constant
     ForceRadius=100.000000
     ForceScale=5.000000
}
